package com.ruoyi.system.controller;

import java.net.URLEncoder;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.util.ListUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.domain.excel.ProvideMoneyExcecl;
import com.ruoyi.system.domain.excel.ProvideMoneyExcelDetail;
import com.ruoyi.system.domain.excel.ProvideRecordsdExcel;
import com.ruoyi.system.domain.excel.ProvideWareExcel;
import com.ruoyi.system.service.impl.InvoiceGroupServiceImpl;
import com.ruoyi.system.service.impl.ProvideInfoServiceImpl;
import com.ruoyi.system.service.impl.ProvideWareServiceImpl;
import com.ruoyi.system.util.DateUtil;
import lombok.SneakyThrows;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IProvideRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 配件库开票明细Controller
 * 
 * @author ruoyi
 * @date 2024-05-07
 */
@RestController
@RequestMapping("/system/provideRecords")
public class ProvideRecordsController extends BaseController
{
    @Autowired
    private IProvideRecordsService provideRecordsService;
    @Autowired
    private InvoiceGroupServiceImpl invoiceGroupService;
    @Autowired
    private ProvideWareServiceImpl provideWareService;
    @Autowired
    private ProvideInfoServiceImpl provideInfoService;

    @GetMapping("/list")
    public AjaxResult list(HttpServletResponse response, ProvideRecords provideRecords,
                           @RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
                           @RequestParam(value = "pageSize",defaultValue = "10") int pageSize) {
        List<ProvideRecords> list = provideRecordsService.selectProvideRecordsList(provideRecords);
        Double sumMoney = 0.0;
        Double totalMoney = 0.0;
        Double getMoney = provideRecordsService.selectSumMoney(provideRecords.getProvide(), provideRecords.getStartTime(), provideRecords.getWarehouseCode());
        if (getMoney != null && getMoney > 0.0) {
            sumMoney = getMoney;
        }
        Double getTotalMoney = provideRecordsService.setlectSumProductMoney(provideRecords.getProvide(), provideRecords.getStartTime(), provideRecords.getWarehouseCode());
        if (getTotalMoney != null && getTotalMoney > 0.0) {
            totalMoney = getTotalMoney;
        }

        // 解决客修的额外编号计算总额问题
        if (provideRecords.getWarehouseCode() != null && provideRecords.getWarehouseCode().equals("000023")) {
            provideRecords.setWarehouseCode("00002000");
            List<ProvideRecords> list1 = provideRecordsService.selectProvideRecordsList(provideRecords);
            list.addAll(list1);
            provideRecords.setWarehouseCode("00002100");
            List<ProvideRecords> list2 = provideRecordsService.selectProvideRecordsList(provideRecords);
            list.addAll(list2);

            Double money1 = provideRecordsService.selectSumMoney(provideRecords.getProvide(), provideRecords.getStartTime(), "00002000");
            if (money1 != null && money1 > 0) {
                sumMoney += money1;
            }
            Double money2 = provideRecordsService.setlectSumProductMoney(provideRecords.getProvide(), provideRecords.getStartTime(), "00002000");
            if (money2 != null && money2 > 0) {
                totalMoney += money2;
            }
            Double money3 = provideRecordsService.selectSumMoney(provideRecords.getProvide(), provideRecords.getStartTime(), "00002100");
            if (money3 != null && money3 > 0) {
                sumMoney += money3;
            }
            Double money4 = provideRecordsService.setlectSumProductMoney(provideRecords.getProvide(), provideRecords.getStartTime(), "00002100");
            if (money4 != null && money4 > 0) {
                totalMoney += money4;
            }
        }

        // 对列表进行分页处理
        int total = list.size();
        int startIndex = (pageNum - 1) * pageSize;
        int endIndex = Math.min(startIndex + pageSize, total);
        List<ProvideRecords> paginatedList = list.subList(startIndex, endIndex);

        // 设置响应头
        DecimalFormat df = new DecimalFormat("0.00##");
        response.setHeader("sumMoney", df.format(sumMoney));
        response.setHeader("totalMoney", df.format(totalMoney));

        // 返回分页结果
        Map<String, Object> result = new HashMap<>();
        result.put("list", paginatedList);
        result.put("total", total);
        result.put("pageNum", pageNum);
        result.put("pageSize", pageSize);

        return AjaxResult.success(result);
    }



    /**
     * 导出配件库开票明细列表-物资公司
     */
    @Log(title = "配件库开票明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ProvideRecords provideRecords)
    {
        List<ProvideRecords> list = provideRecordsService.selectProvideRecordsList(provideRecords);
        ExcelUtil<ProvideRecords> util = new ExcelUtil<ProvideRecords>(ProvideRecords.class);
        util.exportExcel(response, list, "产品明细数据");
    }

    /**
     * 导出配件库开票明细列表-供应商
     */
    @Log(title = "配件库开票明细", businessType = BusinessType.EXPORT)
    @PostMapping("/exportProvide")
    public void exportProvide(HttpServletResponse response, ProvideRecords provideRecords)
    {
        List<ProvideRecords> list = provideRecordsService.selectProvideRecordsList(provideRecords);
        List<ProvideRecordsdExcel> list1 = new ArrayList<>();
        for (ProvideRecords provideRecords1:list) {
            ProvideRecordsdExcel provideRecordsdExcel =  new ProvideRecordsdExcel();
            provideRecordsdExcel.setProvide(provideRecords1.getProvide());
            provideRecordsdExcel.setProductCode(provideRecords1.getProductCode());
            provideRecordsdExcel.setBusCode(provideRecords1.getBusCode());
            provideRecordsdExcel.setCompany(provideRecords1.getCompany());
            provideRecordsdExcel.setWarehouseCode(provideRecords1.getWarehouseCode());
            provideRecordsdExcel.setWarehouseName(provideRecords1.getWarehouseName());
            provideRecordsdExcel.setModel(provideRecords1.getModel());
            provideRecordsdExcel.setPlarnPrice(provideRecords1.getPlarnPrice());
            provideRecordsdExcel.setProductBrand(provideRecords1.getProductBrand());
            provideRecordsdExcel.setProductCount(provideRecords1.getProductCount());
            provideRecordsdExcel.setProductMoney(provideRecords1.getProductMoney());
            provideRecordsdExcel.setProductName(provideRecords1.getProductName());
            provideRecordsdExcel.setProductPrice(provideRecords1.getProductPrice());
            provideRecordsdExcel.setSettlementMode(provideRecords1.getSettlementMode());
            provideRecordsdExcel.setSpecs(provideRecords1.getSpecs());
            provideRecordsdExcel.setRepairBillCode(provideRecords1.getRepairBillCode());
            provideRecordsdExcel.setStatus(provideRecords1.getStatus());
            list1.add(provideRecordsdExcel);
        }
        ExcelUtil<ProvideRecordsdExcel> util = new ExcelUtil<>(ProvideRecordsdExcel.class);
        util.exportExcel(response, list1, "产品明细数据");
    }

    /**
     * 获取配件库开票明细详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(provideRecordsService.selectProvideRecordsById(id));
    }

    /**
     * 新增配件库开票明细
     */
    @Log(title = "配件库开票明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProvideRecords provideRecords)
    {
        return toAjax(provideRecordsService.insertProvideRecords(provideRecords));
    }

    /**
     * 修改配件库开票明细
     */
    @Log(title = "配件库开票明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProvideRecords provideRecords)
    {
        return toAjax(provideRecordsService.updateProvideRecords(provideRecords));
    }

    /**
     * 删除配件库开票明细
     */
    @Log(title = "配件库开票明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(provideRecordsService.deleteProvideRecordsByIds(ids));
    }

    @RequestMapping("addProductCode")
    public AjaxResult addProductCode()
    {
        List<String> list = invoiceGroupService.selectProductCode();
        List<String> list1 = provideRecordsService.selectProductCode(list);
        for (String str:list1) {
            InvoiceGroup invoiceGroup = new InvoiceGroup();
            invoiceGroup.setProductCode(str);
            invoiceGroup.setProductGroup("配件");
            invoiceGroupService.insertInvoiceGroup(invoiceGroup);
        }
        return success();
    }

    /**
     * 查询配件库开票明细列表-供应商跳转仓库详情
     */
    @GetMapping("/listProvideWareRecords")
    public AjaxResult listProvideWareRecords(HttpServletResponse response, @RequestParam(value = "wareHouseCode",required = false)String wareHouseCode,@RequestParam(value = "createTime",required = false)String createTime,@RequestParam(value = "provide",required = false)String provide)
    {
        List<Map<String,Object>> hashMapList = new ArrayList<>();
        DecimalFormat df = new DecimalFormat("0.00##");
        ProvideWare provideWare = new ProvideWare();
        if(wareHouseCode!=null&& !wareHouseCode.equals("")){
            provideWare.setWareCode(wareHouseCode);
        }
        List<ProvideWare> provideWares = provideWareService.selectProvideWareList(provideWare);
        for (ProvideWare provideWare1:provideWares) {
            Map<String,Object> wareMap = new HashMap<>();
            wareMap.put("inMoney","0");
            wareMap.put("outMoney","0");
            wareMap.put("totalMoney","0");
            wareMap.put("recordsMoney","0");
            wareMap.put("saleMoney","0");
            wareMap.put("diffMoney","0");
            wareMap.put("warehouse_code",provideWare1.getWareCode());
            wareMap.put("warehouse_name",provideWare1.getWareName());
            List<Map<String, Object>> maps = provideRecordsService.selectOutWareMoney(provideWare1.getWareCode(),createTime,provide);
            String outMoney = "0";
            String inMoney = "0";
            for (Map<String,Object> map:maps) {
               if(map.get("settlement_mode").equals("压库")){
                   outMoney = df.format(Double.valueOf(outMoney)+Double.valueOf(map.get("money").toString()));
                   wareMap.put("outMoney",outMoney);
               }else{
                   inMoney = df.format(Double.valueOf(inMoney)+Double.valueOf(map.get("money").toString()));
                   wareMap.put("inMoney",inMoney);
               }
            }
            if(provideWare1.getWareCode().equals("000023")){
                List<Map<String, Object>> maps1 = provideRecordsService.selectOutWareMoney("00002000",createTime,provide);
                for (Map<String,Object> map:maps1) {
                    if(map.get("settlement_mode").equals("压库")){
                        outMoney = df.format(Double.valueOf(outMoney)+Double.valueOf(map.get("money").toString()));
                        wareMap.put("outMoney",outMoney);
                    }else{
                        inMoney = df.format(Double.valueOf(inMoney)+Double.valueOf(map.get("money").toString()));
                        wareMap.put("inMoney",inMoney);
                    }
                }

                List<Map<String, Object>> maps2 = provideRecordsService.selectOutWareMoney("00002100",createTime,provide);
                for (Map<String,Object> map:maps2) {
                    if(map.get("settlement_mode").equals("压库")){
                        outMoney = df.format(Double.valueOf(outMoney)+Double.valueOf(map.get("money").toString()));
                        wareMap.put("outMoney",outMoney);
                    }else{
                        inMoney = df.format(Double.valueOf(inMoney)+Double.valueOf(map.get("money").toString()));
                        wareMap.put("inMoney",inMoney);
                    }
                }
            }

            String totalMoney = df.format(Double.valueOf(wareMap.get("outMoney").toString())+Double.valueOf(wareMap.get("inMoney").toString()));
            String recordsMoney = df.format(Double.valueOf(wareMap.get("outMoney").toString())+Double.valueOf(wareMap.get("inMoney").toString()));
            wareMap.put("totalMoney",totalMoney);
            wareMap.put("recordsMoney",recordsMoney);
            hashMapList.add(wareMap);
        }
        Double sumMoney = 0.0;
        Double getMoney = provideRecordsService.selectSumMoney(provide, createTime, wareHouseCode);
        if(getMoney!=null&&getMoney>0.0){
            sumMoney=getMoney;
        }
        //解决客修的额外编号问题
        if(wareHouseCode.equals("000023")) {
             Double money1 = provideRecordsService.selectSumMoney(provide, createTime, "00002000");
             Double money2= provideRecordsService.selectSumMoney(provide, createTime, "00002100");
            if(money1!=null&&money1>0.0){
                sumMoney = sumMoney + money1;
            }
            if(money2!=null&&money2>0.0){
                sumMoney = sumMoney + money2;
            }
        }
        response.setHeader("sumMoney",df.format(sumMoney));
        return AjaxResult.success(hashMapList);
    }


    /**
     * 仓库明细
     */
    @GetMapping("/listProvideWareOutRecords")
    public AjaxResult listProvideWareOutRecords(HttpServletResponse response, @RequestParam(value = "wareHouseCode",required = false)String wareHouseCode,@RequestParam(value = "createTime",required = false)String createTime,@RequestParam(value = "provide",required = false)String provide)
    {
        List<Map<String,Object>> hashMapList = new ArrayList<>();
        DecimalFormat df = new DecimalFormat("0.00##");
        ProvideWare provideWare = new ProvideWare();
        if(wareHouseCode!=null&& !wareHouseCode.equals("")){
            provideWare.setWareCode(wareHouseCode);
        }
        List<ProvideWare> provideWares = provideWareService.selectProvideWareList(provideWare);
        for (ProvideWare provideWare1:provideWares) {
            Map<String,Object> wareMap = new HashMap<>();
            wareMap.put("inMoney","0");
            wareMap.put("outMoney","0");
            wareMap.put("totalMoney","0");
            wareMap.put("recordsMoney","0");
            wareMap.put("saleMoney","0");
            wareMap.put("diffMoney","0");
            wareMap.put("warehouse_code",provideWare1.getWareCode());
            wareMap.put("warehouse_name",provideWare1.getWareName());
            //售价计算
            List<Map<String, Object>> mapss = provideRecordsService.selectWareMoney(provideWare1.getWareCode(),createTime,provide);
            String productInMoney = "0";
            String productOutMoney = "0";
            for (Map<String,Object> map:mapss) {
                if(map.get("settlement_mode").equals("压库")){
                    productOutMoney = df.format(Double.valueOf(productOutMoney)+Double.valueOf(map.get("money").toString()));
                    wareMap.put("outMoney",productOutMoney);
                }else{
                    productInMoney = df.format(Double.valueOf(productInMoney)+Double.valueOf(map.get("money").toString()));
                    wareMap.put("inMoney",productInMoney);
                }
            }
            if(provideWare1.getWareCode().equals("000023")){
                List<Map<String, Object>> maps1 = provideRecordsService.selectWareMoney("00002000",createTime,provide);
                for (Map<String,Object> map:maps1) {
                    if(map.get("settlement_mode").equals("压库")){
                        productOutMoney = df.format(Double.valueOf(productOutMoney)+Double.valueOf(map.get("money").toString()));
                        wareMap.put("outMoney",productOutMoney);
                    }else{
                        productInMoney = df.format(Double.valueOf(productInMoney)+Double.valueOf(map.get("money").toString()));
                        wareMap.put("inMoney",productInMoney);
                    }
                }

                List<Map<String, Object>> maps2 = provideRecordsService.selectWareMoney("00002100",createTime,provide);
                for (Map<String,Object> map:maps2) {
                    if(map.get("settlement_mode").equals("压库")){
                        productOutMoney = df.format(Double.valueOf(productOutMoney)+Double.valueOf(map.get("money").toString()));
                        wareMap.put("outMoney",productOutMoney);
                    }else{
                        productInMoney = df.format(Double.valueOf(productInMoney)+Double.valueOf(map.get("money").toString()));
                        wareMap.put("inMoney",productInMoney);
                    }
                }
            }
            String totalMoney = df.format(Double.valueOf(wareMap.get("outMoney").toString())+Double.valueOf(wareMap.get("inMoney").toString()));
            wareMap.put("totalMoney",totalMoney);

            //进价计算
            List<Map<String, Object>> maps = provideRecordsService.selectOutWareMoney(provideWare1.getWareCode(),createTime,provide);
            String outMoney = "0";
            String inMoney = "0";
            for (Map<String,Object> map:maps) {
                if(map.get("settlement_mode").equals("压库")){
                    outMoney = df.format(Double.valueOf(outMoney)+Double.valueOf(map.get("money").toString()));
//                    wareMap.put("outMoney",outMoney);
                }else{
                    inMoney = df.format(Double.valueOf(inMoney)+Double.valueOf(map.get("money").toString()));
//                    wareMap.put("inMoney",inMoney);
                }
            }
            if(provideWare1.getWareCode().equals("000023")){
                List<Map<String, Object>> maps1 = provideRecordsService.selectOutWareMoney("00002000",createTime,provide);
                for (Map<String,Object> map:maps1) {
                    if(map.get("settlement_mode").equals("压库")){
                        outMoney = df.format(Double.valueOf(outMoney)+Double.valueOf(map.get("money").toString()));
//                        wareMap.put("outMoney",outMoney);
                    }else{
                        inMoney = df.format(Double.valueOf(inMoney)+Double.valueOf(map.get("money").toString()));
//                        wareMap.put("inMoney",inMoney);
                    }
                }

                List<Map<String, Object>> maps2 = provideRecordsService.selectOutWareMoney("00002100",createTime,provide);
                for (Map<String,Object> map:maps2) {
                    if(map.get("settlement_mode").equals("压库")){
                        outMoney = df.format(Double.valueOf(outMoney)+Double.valueOf(map.get("money").toString()));
//                        wareMap.put("outMoney",outMoney);
                    }else{
                        inMoney = df.format(Double.valueOf(inMoney)+Double.valueOf(map.get("money").toString()));
//                        wareMap.put("inMoney",inMoney);
                    }
                }
            }
            String recordsMoney = df.format(Double.valueOf(outMoney)+Double.valueOf(inMoney));
            //进价总金额
            wareMap.put("recordsMoney",recordsMoney);
            String diffMoney = df.format(Double.valueOf(totalMoney) - Double.valueOf(recordsMoney));
            wareMap.put("diffMoney",diffMoney);
            hashMapList.add(wareMap);
        }
        Double sumMoney = 0.0;
        Double getMoney = provideRecordsService.setlectSumProductMoney(provide, createTime, wareHouseCode);
        if(getMoney!=null&&getMoney>0.0){
            sumMoney=getMoney;
        }
        //解决客修的额外编号问题
        if(wareHouseCode.equals("000023")) {
            Double money1 = provideRecordsService.setlectSumProductMoney(provide, createTime, "00002000");
            Double money2= provideRecordsService.setlectSumProductMoney(provide, createTime, "00002100");
            if(money1!=null&&money1>0.0){
                sumMoney = sumMoney + money1;
            }
            if(money2!=null&&money2>0.0){
                sumMoney = sumMoney + money2;
        }
        }
        //补充计算总进价金额
        Double totalProductMoney = 0.0;
        Double money = provideRecordsService.selectSumMoney(provide, createTime, wareHouseCode);
        if(money!=null&&money>0.0){
            totalProductMoney=money;
        }
        if(wareHouseCode.equals("000023")){
            Double money1 = provideRecordsService.selectSumMoney(provide, createTime, "00002000");
            Double money2= provideRecordsService.selectSumMoney(provide, createTime, "00002100");
            if(money1!=null&&money1>0.0){
                totalProductMoney = totalProductMoney + money1;
            }
            if(money2!=null&&money2>0.0){
                totalProductMoney = totalProductMoney + money2;
            }
        }
        response.setHeader("sumMoney",df.format(sumMoney));
        response.setHeader("sumInMoney",df.format(totalProductMoney));
        return AjaxResult.success(hashMapList);
    }

    /**
     * 导出配件库开票-仓库详情
     */
    @SneakyThrows
    @RequestMapping("/exportProvideWare")
    public void exportProvideWare(HttpServletResponse response, @RequestParam(value = "wareHouseCode",required = false)String wareHouseCode,@RequestParam(value = "createTime",required = false)String createTime,@RequestParam(value = "provide",required = false)String provide)
    {
        List<ProvideWareExcel> list = new ArrayList<>();
        DecimalFormat df = new DecimalFormat("0.00##");
        ProvideWare provideWare = new ProvideWare();
        if(wareHouseCode!=null&& !wareHouseCode.equals("")){
            provideWare.setWareCode(wareHouseCode);
        }
        List<ProvideWare> provideWares = provideWareService.selectProvideWareList(provideWare);
        logger.info(String.valueOf(provideWares.size()));
        for (ProvideWare provideWare1:provideWares) {
            Map<String,Object> wareMap = new HashMap<>();
            wareMap.put("inMoney","0");
            wareMap.put("outMoney","0");
            wareMap.put("totalMoney","0");
            wareMap.put("recordsMoney","0");
            wareMap.put("saleMoney","0");
            wareMap.put("diffMoney","0");
            wareMap.put("warehouse_code",provideWare1.getWareCode());
            wareMap.put("warehouse_name",provideWare1.getWareName());
            List<Map<String, Object>> maps = provideRecordsService.selectOutWareMoney(provideWare1.getWareCode(),createTime,provide);
            String outMoney = "0";
            String inMoney = "0";
            for (Map<String,Object> map:maps) {
                if(map.get("settlement_mode").equals("压库")){
                    outMoney = df.format(Double.valueOf(outMoney)+Double.valueOf(map.get("money").toString()));
                    wareMap.put("outMoney",outMoney);
                }else{
                    inMoney = df.format(Double.valueOf(inMoney)+Double.valueOf(map.get("money").toString()));
                    wareMap.put("inMoney",inMoney);
                }
            }
            String totalMoney = df.format(Double.valueOf(wareMap.get("outMoney").toString())+Double.valueOf(wareMap.get("inMoney").toString()));
            String recordsMoney = df.format(Double.valueOf(wareMap.get("outMoney").toString())+Double.valueOf(wareMap.get("inMoney").toString()));
            wareMap.put("totalMoney",totalMoney);
            wareMap.put("recordsMoney",recordsMoney);
            ProvideWareExcel provideWareExcel = new ProvideWareExcel();
            provideWareExcel.setRecordsMoney(wareMap.get("recordsMoney").toString());
            provideWareExcel.setInMoney(wareMap.get("inMoney").toString());
            provideWareExcel.setOutMoney(wareMap.get("outMoney").toString());
            provideWareExcel.setTotalMoney(wareMap.get("totalMoney").toString());
            provideWareExcel.setSaleMoney(wareMap.get("saleMoney").toString());
            provideWareExcel.setDiffMoney(wareMap.get("diffMoney").toString());
            provideWareExcel.setWarehouseCode(wareMap.get("warehouse_code").toString());
            provideWareExcel.setWarehouseName(wareMap.get("warehouse_name").toString());
            list.add(provideWareExcel);
        }
        ExcelUtil<ProvideWareExcel> util = new ExcelUtil<ProvideWareExcel>(ProvideWareExcel.class);
        util.exportExcel(response, list, "仓库明细数据");
    }

    /**
     * 导出配件库开票-仓库明细
     */
    @SneakyThrows
    @RequestMapping("/exportOutProvideWare")
    public void exportOutProvideWare(HttpServletResponse response, @RequestParam(value = "wareHouseCode",required = false)String wareHouseCode,@RequestParam(value = "createTime",required = false)String createTime,@RequestParam(value = "provide",required = false)String provide)
    {
        List<ProvideWareExcel> list = new ArrayList<>();
        DecimalFormat df = new DecimalFormat("0.00##");
        ProvideWare provideWare = new ProvideWare();
        if(wareHouseCode!=null&& !wareHouseCode.equals("")){
            provideWare.setWareCode(wareHouseCode);
        }
        List<ProvideWare> provideWares = provideWareService.selectProvideWareList(provideWare);
        for (ProvideWare provideWare1:provideWares) {
            Map<String,Object> wareMap = new HashMap<>();
            wareMap.put("inMoney","0");
            wareMap.put("outMoney","0");
            wareMap.put("totalMoney","0");
            wareMap.put("recordsMoney","0");
            wareMap.put("saleMoney","0");
            wareMap.put("diffMoney","0");
            wareMap.put("warehouse_code",provideWare1.getWareCode());
            wareMap.put("warehouse_name",provideWare1.getWareName());
            List<Map<String, Object>> maps = provideRecordsService.selectOutWareMoney(provideWare1.getWareCode(),createTime,provide);
            String outMoney = "0";
            String inMoney = "0";
            for (Map<String,Object> map:maps) {
                if(map.get("settlement_mode").equals("压库")){
                    outMoney = df.format(Double.valueOf(outMoney)+Double.valueOf(map.get("money").toString()));
                    wareMap.put("outMoney",outMoney);
                }else{
                    inMoney = df.format(Double.valueOf(inMoney)+Double.valueOf(map.get("money").toString()));
                    wareMap.put("inMoney",inMoney);
                }
            }
            String totalMoney = df.format(Double.valueOf(wareMap.get("outMoney").toString())+Double.valueOf(wareMap.get("inMoney").toString()));
            String recordsMoney = df.format(Double.valueOf(wareMap.get("outMoney").toString())+Double.valueOf(wareMap.get("inMoney").toString()));
            wareMap.put("totalMoney",totalMoney);
            wareMap.put("recordsMoney",recordsMoney);
            ProvideWareExcel provideWareExcel = new ProvideWareExcel();
            provideWareExcel.setRecordsMoney(wareMap.get("recordsMoney").toString());
            provideWareExcel.setInMoney(wareMap.get("inMoney").toString());
            provideWareExcel.setOutMoney(wareMap.get("outMoney").toString());
            provideWareExcel.setTotalMoney(wareMap.get("totalMoney").toString());
            provideWareExcel.setSaleMoney(wareMap.get("saleMoney").toString());
            provideWareExcel.setDiffMoney(wareMap.get("diffMoney").toString());
            provideWareExcel.setWarehouseCode(wareMap.get("warehouse_code").toString());
            provideWareExcel.setWarehouseName(wareMap.get("warehouse_name").toString());
            list.add(provideWareExcel);
        }
        ExcelUtil<ProvideWareExcel> util = new ExcelUtil<ProvideWareExcel>(ProvideWareExcel.class);
        util.exportExcel(response, list, "仓库明细数据");
    }

    /**
     * 供应商付款
     */
    @SneakyThrows
    @RequestMapping("/selectProvideWareMoney")
    public AjaxResult selectProvideWareMoney(HttpServletResponse response,@RequestParam(value = "createTime",required = false)String createTime,@RequestParam(value = "provide",required = false)String provide) {
        List<Map<String, Object>> returnList = new ArrayList<>();
        DecimalFormat df = new DecimalFormat("0.00##");
        List<String> list1 = provideRecordsService.selectProvideList(provide);
        String headerOutTotalMoney = "0";
        String headerInTotalMoney = "0";
        for (String provide1 : list1) {
            List<Map<String, Object>> maps = provideRecordsService.selectProvideWareMoney(createTime, provide1);
            Map<String, Object> wareMap = new HashMap<>();
            wareMap.put("provide", provide1);
            ProvideInfo provideInfo = new ProvideInfo();
            provideInfo.setName(provide1);
            List<ProvideInfo> provideInfos = provideInfoService.selectProvideInfoList(provideInfo);
            if(provideInfos!=null&& provideInfos.size()>0){
                wareMap.put("financeCode", provideInfos.get(0).getFinanceCode());
            }else{
                wareMap.put("financeCode", "");
            }
            Double outTotalMoney = 0.0;
            Double RoutTotalMoney = 0.0;
            Double inTotalMoney = 0.0;
            Double RinTotalMoney = 0.0;
            Double outBus1 = 0.0;
            Double outBus2 = 0.0;
            Double outBus3 = 0.0;
            Double outBus4 = 0.0;
            Double outBus5 = 0.0;
            Double RoutBus1 = 0.0;
            Double RoutBus2 = 0.0;
            Double RoutBus3 = 0.0;
            Double RoutBus4 = 0.0;
            Double RoutBus5 = 0.0;
            Double outJs = 0.0;
            Double RoutJs = 0.0;
            Double outCm = 0.0;
            Double RoutCm = 0.0;
            Double outKx = 0.0;
            Double RoutKx = 0.0;
            Double inBus1 = 0.0;
            Double inBus2 = 0.0;
            Double inBus3 = 0.0;
            Double inBus4 = 0.0;
            Double inBus5 = 0.0;
            Double RinBus1 = 0.0;
            Double RinBus2 = 0.0;
            Double RinBus3 = 0.0;
            Double RinBus4 = 0.0;
            Double RinBus5 = 0.0;
            Double inJs = 0.0;
            Double RinJs = 0.0;
            Double inCm = 0.0;
            Double RinCm = 0.0;
            Double inKx = 0.0;
            Double RinKx = 0.0;
            for (Map<String, Object> map : maps) {
                if (map.get("warehouse_code").toString().substring(0, 6).equals("000002")) {   //巴士一公司
                    if(map.get("product_group").equals("润滑油")){
                        RoutBus1 += Double.valueOf(map.get("outMoney").toString());
                        RinBus1 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outBus1 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        inBus1 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                } else if (map.get("warehouse_code").toString().substring(0, 6).equals("000009")) {//巴士二公司
                    if(map.get("product_group").equals("润滑油")){
                        RoutBus2 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        RinBus2 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outBus2 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                        inBus2 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                } else if (map.get("warehouse_code").toString().substring(0, 6).equals("000010")) {//巴士三公司
                    if(map.get("product_group").equals("润滑油")){
                        RoutBus3 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        RinBus3 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outBus3 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                        inBus3 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                } else if (map.get("warehouse_code").toString().substring(0, 6).equals("000018")) {//巴士四公司
                    if(map.get("product_group").equals("润滑油")){
                        RoutBus4 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        RinBus4 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outBus4 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                        inBus4 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                } else if (map.get("warehouse_code").toString().substring(0, 6).equals("000023")||map.get("warehouse_code").toString().substring(0, 6).equals("000020")||map.get("warehouse_code").toString().substring(0, 6).equals("000021")) {//客修
                    if(map.get("product_group").equals("润滑油")){
                        RoutKx += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        RinKx += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outKx += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        inKx += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                } else if (map.get("warehouse_code").toString().substring(0, 6).equals("000017")) {//巴士五公司
                    if(map.get("product_group").equals("润滑油")){
                        RoutBus5 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        RinBus5 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outBus5 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        inBus5 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                }else if (map.get("warehouse_code").toString().substring(0, 6).equals("000015")) {//金山仓库
                    if(map.get("product_group").equals("润滑油")){
                        RoutJs += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        RinJs += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outJs += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                        inJs += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                }else if (map.get("warehouse_code").toString().substring(0, 6).equals("000013")) {//崇明仓库
                    if(map.get("product_group").equals("润滑油")){
                        RoutCm += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        RinCm += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outCm += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                        inCm += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                }
            }
            wareMap.put("outBus1", outBus1);
            wareMap.put("outBus2", outBus2);
            wareMap.put("outBus3", outBus3);
            wareMap.put("outBus4", outBus4);
            wareMap.put("outBus5", outBus5);
            wareMap.put("RoutBus1", RoutBus1);
            wareMap.put("RoutBus2", RoutBus2);
            wareMap.put("RoutBus3", RoutBus3);
            wareMap.put("RoutBus4", RoutBus4);
            wareMap.put("RoutBus5", RoutBus5);
            wareMap.put("outJs", outJs);
            wareMap.put("outCm", outCm);
            wareMap.put("outKx", outKx);
            wareMap.put("RoutKx", RoutKx);
            wareMap.put("RoutCm", RoutCm);
            wareMap.put("RoutJs", RoutJs);
            wareMap.put("inBus1", inBus1);
            wareMap.put("inBus2", inBus2);
            wareMap.put("inBus3", inBus3);
            wareMap.put("inBus4", inBus4);
            wareMap.put("inBus5", inBus5);
            wareMap.put("RinBus1", RinBus1);
            wareMap.put("RinBus2", RinBus2);
            wareMap.put("RinBus3", RinBus3);
            wareMap.put("RinBus4", RinBus4);
            wareMap.put("RinBus5", RinBus5);
            wareMap.put("inJs", inJs);
            wareMap.put("inCm", inCm);
            wareMap.put("inKx", inKx);
            wareMap.put("RinKx", RinKx);
            wareMap.put("RinJs", RinJs);
            wareMap.put("RinCm", RinCm);
            wareMap.put("createTime",createTime);
            wareMap.put("outTotalMoney",outTotalMoney);
            wareMap.put("RoutTotalMoney",RoutTotalMoney);
            wareMap.put("inTotalMoney",inTotalMoney);
            wareMap.put("RinTotalMoney",RinTotalMoney);
            headerOutTotalMoney = df.format(Double.valueOf(outTotalMoney) + Double.valueOf(RoutTotalMoney) + Double.valueOf(headerOutTotalMoney));
            headerInTotalMoney = df.format(Double.valueOf(inTotalMoney) + Double.valueOf(RinTotalMoney) + Double.valueOf(headerInTotalMoney));
            returnList.add(wareMap);
        }
        response.setHeader("headerOutTotalMoney",headerOutTotalMoney);
        response.setHeader("headerInTotalMoney",headerInTotalMoney);
        return AjaxResult.success(returnList);
    }


    /**
     * 导出配件库开票-月结清单-全部
     */
    @SneakyThrows
    @RequestMapping("/exportProvideWareMoney")
    public void exportProvideWareMoney(HttpServletResponse response,@RequestParam(value = "createTime",required = false)String createTime,
                                       @RequestParam(value = "provide",required = false)String provide)
    {
        List<ProvideMoneyExcecl> returnList = new ArrayList<>();
        DecimalFormat df = new DecimalFormat("0.00##");
        List<String> list1 = provideRecordsService.selectProvideList(provide);
        for (String provide1 : list1) {
            ProvideMoneyExcecl provideMoneyExcecl = new ProvideMoneyExcecl();
            List<Map<String, Object>> maps = provideRecordsService.selectProvideWareMoney(createTime, provide1);
            Map<String, Object> wareMap = new HashMap<>();
            wareMap.put("provide", provide1);
            ProvideInfo provideInfo = new ProvideInfo();
            provideInfo.setName(provide1);
            List<ProvideInfo> provideInfos = provideInfoService.selectProvideInfoList(provideInfo);
            if(provideInfos!=null&& provideInfos.size()>0){
                provideMoneyExcecl.setFinanceCode(provideInfos.get(0).getFinanceCode());
            }else{
                provideMoneyExcecl.setFinanceCode("");
            }
            Double outTotalMoney = 0.0;
            Double inTotalMoney = 0.0;
            Double outBus1 = 0.0;
            Double outBus2 = 0.0;
            Double outBus3 = 0.0;
            Double outBus4 = 0.0;
            Double outBus5 = 0.0;
            Double outJs = 0.0;
            Double outCm = 0.0;
            Double outKx = 0.0;
            Double inBus1 = 0.0;
            Double inBus2 = 0.0;
            Double inBus3 = 0.0;
            Double inBus4 = 0.0;
            Double inBus5 = 0.0;
            Double inJs = 0.0;
            Double inCm = 0.0;
            Double inKx = 0.0;
            for (Map<String, Object> map : maps) {
                if (map.get("warehouse_code").toString().substring(0, 6).equals("000002")) {   //巴士一公司
                    outBus1 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                    inBus1 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                    outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                    inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                } else if (map.get("warehouse_code").toString().substring(0, 6).equals("000009")) {//巴士二公司
                    outBus2 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                    inBus2 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                    outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                    inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                } else if (map.get("warehouse_code").toString().substring(0, 6).equals("000010")) {//巴士三公司
                    outBus3 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                    inBus3 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                    outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                    inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                } else if (map.get("warehouse_code").toString().substring(0, 6).equals("000018")) {//巴士四公司
                    outBus4 +=  Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                    inBus4 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                    outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                    inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                } else if (map.get("warehouse_code").toString().substring(0, 6).equals("000023")||map.get("warehouse_code").toString().substring(0, 6).equals("000020")||map.get("warehouse_code").toString().substring(0, 6).equals("000021")) {//客修
                    outKx += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                    inKx += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                    outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                    inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                } else if (map.get("warehouse_code").toString().substring(0, 6).equals("000017")) {//巴士五公司
                    outBus5 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                    inBus5 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                    outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                    inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                }else if (map.get("warehouse_code").toString().substring(0, 6).equals("000015")) {//金山仓库
                    outJs += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                    inJs += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                    outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                    inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                }else if (map.get("warehouse_code").toString().substring(0, 6).equals("000013")) {//崇明仓库
                    outCm += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                    inCm += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                    outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                    inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                }
            }
            provideMoneyExcecl.setProvide(provide1);
            provideMoneyExcecl.setOutBus1(df.format(outBus1));
            provideMoneyExcecl.setOutBus2(df.format(outBus2));
            provideMoneyExcecl.setOutBus3(df.format(outBus3));
            provideMoneyExcecl.setOutBus4(df.format(outBus4));
            provideMoneyExcecl.setOutBus5(df.format(outBus5));
            provideMoneyExcecl.setOutCm(df.format(outCm));
            provideMoneyExcecl.setOutKx(df.format(outKx));
            provideMoneyExcecl.setOutJs(df.format(outJs));
            provideMoneyExcecl.setInBus1(df.format(inBus1));
            provideMoneyExcecl.setInBus2(df.format(inBus2));
            provideMoneyExcecl.setInBus3(df.format(inBus3));
            provideMoneyExcecl.setInBus4(df.format(inBus4));
            provideMoneyExcecl.setInBus5(df.format(inBus5));
            provideMoneyExcecl.setInKx(df.format(inKx));
            provideMoneyExcecl.setInCm(df.format(inCm));
            provideMoneyExcecl.setInJs(df.format(inJs));
            provideMoneyExcecl.setCreateTime(createTime);
            provideMoneyExcecl.setOutTotalMoney(df.format(outTotalMoney));
            provideMoneyExcecl.setInTotalMoney(df.format(inTotalMoney));
            returnList.add(provideMoneyExcecl);
        }
        ExcelUtil<ProvideMoneyExcecl> util = new ExcelUtil<ProvideMoneyExcecl>(ProvideMoneyExcecl.class);
        util.exportExcel(response, returnList, "供应商16点数据");
    }




    /**
     * 导出配件库开票-月结清单-详情
     */
    @SneakyThrows
    @RequestMapping("/exportProvideWareMoneyDetail")
    public void exportProvideWareMoneyDetail(HttpServletResponse response,@RequestParam(value = "createTime",required = false)String createTime,
                                       @RequestParam(value = "provide",required = false)String provide)
    {
        List<ProvideMoneyExcelDetail> returnList = new ArrayList<>();
        DecimalFormat df = new DecimalFormat("0.00##");
        List<String> list1 = provideRecordsService.selectProvideList(provide);
        for (String provide1 : list1) {
            ProvideMoneyExcelDetail provideMoneyExcecl = new ProvideMoneyExcelDetail();
            List<Map<String, Object>> maps = provideRecordsService.selectProvideWareMoney(createTime, provide1);
            Map<String, Object> wareMap = new HashMap<>();
            wareMap.put("provide", provide1);
            ProvideInfo provideInfo = new ProvideInfo();
            provideInfo.setName(provide1);
            List<ProvideInfo> provideInfos = provideInfoService.selectProvideInfoList(provideInfo);
            if(provideInfos!=null&& provideInfos.size()>0){
                provideMoneyExcecl.setFinanceCode(provideInfos.get(0).getFinanceCode());
            }else{
                provideMoneyExcecl.setFinanceCode("");
            }
            Double outTotalMoney = 0.0;
            Double RoutTotalMoney = 0.0;
            Double inTotalMoney = 0.0;
            Double RinTotalMoney = 0.0;
            Double outBus1 = 0.0;
            Double outBus2 = 0.0;
            Double outBus3 = 0.0;
            Double outBus4 = 0.0;
            Double outBus5 = 0.0;
            Double RoutBus1 = 0.0;
            Double RoutBus2 = 0.0;
            Double RoutBus3 = 0.0;
            Double RoutBus4 = 0.0;
            Double RoutBus5 = 0.0;
            Double outJs = 0.0;
            Double RoutJs = 0.0;
            Double outCm = 0.0;
            Double RoutCm = 0.0;
            Double outKx = 0.0;
            Double RoutKx = 0.0;
            Double inBus1 = 0.0;
            Double inBus2 = 0.0;
            Double inBus3 = 0.0;
            Double inBus4 = 0.0;
            Double inBus5 = 0.0;
            Double RinBus1 = 0.0;
            Double RinBus2 = 0.0;
            Double RinBus3 = 0.0;
            Double RinBus4 = 0.0;
            Double RinBus5 = 0.0;
            Double inJs = 0.0;
            Double RinJs = 0.0;
            Double inCm = 0.0;
            Double RinCm = 0.0;
            Double inKx = 0.0;
            Double RinKx = 0.0;
            for (Map<String, Object> map : maps) {
                if (map.get("warehouse_code").toString().substring(0, 6).equals("000002")) {   //巴士一公司
                    if(map.get("product_group").equals("润滑油")){
                        RoutBus1 += Double.valueOf(map.get("outMoney").toString());
                        RinBus1 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outBus1 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        inBus1 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                } else if (map.get("warehouse_code").toString().substring(0, 6).equals("000009")) {//巴士二公司
                    if(map.get("product_group").equals("润滑油")){
                        RoutBus2 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        RinBus2 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outBus2 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                        inBus2 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                } else if (map.get("warehouse_code").toString().substring(0, 6).equals("000010")) {//巴士三公司
                    if(map.get("product_group").equals("润滑油")){
                        RoutBus3 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        RinBus3 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outBus3 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                        inBus3 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                } else if (map.get("warehouse_code").toString().substring(0, 6).equals("000018")) {//巴士四公司
                    if(map.get("product_group").equals("润滑油")){
                        RoutBus4 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        RinBus4 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outBus4 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                        inBus4 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                } else if (map.get("warehouse_code").toString().substring(0, 6).equals("000023")||map.get("warehouse_code").toString().substring(0, 6).equals("000020")||map.get("warehouse_code").toString().substring(0, 6).equals("000021")) {//客修
                    if(map.get("product_group").equals("润滑油")){
                        RoutKx += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        RinKx += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outKx += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        inKx += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                } else if (map.get("warehouse_code").toString().substring(0, 6).equals("000017")) {//巴士五公司
                    if(map.get("product_group").equals("润滑油")){
                        RoutBus5 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        RinBus5 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outBus5 += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        inBus5 += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                }else if (map.get("warehouse_code").toString().substring(0, 6).equals("000015")) {//金山仓库
                    if(map.get("product_group").equals("润滑油")){
                        RoutJs += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        RinJs += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outJs += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                        inJs += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                }else if (map.get("warehouse_code").toString().substring(0, 6).equals("000013")) {//崇明仓库
                    if(map.get("product_group").equals("润滑油")){
                        RoutCm += Double.valueOf(Double.valueOf(map.get("outMoney").toString()));
                        RinCm += Double.valueOf(Double.valueOf(map.get("inMoney").toString()));
                        RoutTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        RinTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }else{
                        outCm += Double.valueOf(Double.valueOf(map.get("outMoney").toString()) );
                        inCm += Double.valueOf(Double.valueOf(map.get("inMoney").toString()) );
                        outTotalMoney += Double.valueOf(map.get("outMoney").toString());
                        inTotalMoney += Double.valueOf(map.get("inMoney").toString());
                    }
                }
            }
            provideMoneyExcecl.setProvide(provide1);
            provideMoneyExcecl.setOutBus1(df.format(outBus1));
            provideMoneyExcecl.setRoutBus1(df.format(RoutBus1));
            provideMoneyExcecl.setOutBus2(df.format(outBus2));
            provideMoneyExcecl.setRoutBus2(df.format(RoutBus2));
            provideMoneyExcecl.setOutBus3(df.format(outBus3));
            provideMoneyExcecl.setRoutBus3(df.format(RoutBus3));
            provideMoneyExcecl.setOutBus4(df.format(outBus4));
            provideMoneyExcecl.setRoutBus4(df.format(RoutBus4));
            provideMoneyExcecl.setOutBus5(df.format(outBus5));
            provideMoneyExcecl.setRoutBus5(df.format(RoutBus5));
            provideMoneyExcecl.setOutCm(df.format(outCm));
            provideMoneyExcecl.setRoutCm(df.format(RoutCm));
            provideMoneyExcecl.setOutKx(df.format(outKx));
            provideMoneyExcecl.setRoutKx(df.format(RoutKx));
            provideMoneyExcecl.setOutJs(df.format(outJs));
            provideMoneyExcecl.setRoutJs(df.format(RoutJs));
            provideMoneyExcecl.setInBus1(df.format(inBus1));
            provideMoneyExcecl.setRInBus1(df.format(RinBus1));
            provideMoneyExcecl.setInBus2(df.format(inBus2));
            provideMoneyExcecl.setRInBus2(df.format(RinBus2));
            provideMoneyExcecl.setInBus3(df.format(inBus3));
            provideMoneyExcecl.setRInBus3(df.format(RinBus3));
            provideMoneyExcecl.setInBus4(df.format(inBus4));
            provideMoneyExcecl.setRInBus4(df.format(RinBus4));
            provideMoneyExcecl.setInBus5(df.format(inBus5));
            provideMoneyExcecl.setRInBus5(df.format(RinBus5));
            provideMoneyExcecl.setInKx(df.format(inKx));
            provideMoneyExcecl.setRInKx(df.format(RinKx));
            provideMoneyExcecl.setInCm(df.format(inCm));
            provideMoneyExcecl.setRInCm(df.format(RinCm));
            provideMoneyExcecl.setInJs(df.format(inJs));
            provideMoneyExcecl.setRInJs(df.format(RinJs));
            provideMoneyExcecl.setCreateTime(createTime);
            provideMoneyExcecl.setOutTotalMoney(df.format(outTotalMoney));
            provideMoneyExcecl.setInTotalMoney(df.format(inTotalMoney));
            provideMoneyExcecl.setRInTotalMoney(df.format(RinTotalMoney));
            provideMoneyExcecl.setRoutTotalMoney(df.format(RoutTotalMoney));
            returnList.add(provideMoneyExcecl);
        }
        ExcelUtil<ProvideMoneyExcelDetail> util = new ExcelUtil<ProvideMoneyExcelDetail>(ProvideMoneyExcelDetail.class);
        util.exportExcel(response, returnList, "供应商16点详情数据");
    }




    /**
     * 配件库利润年度报表
     */
    @GetMapping("/listPjProfitMoney")
    public AjaxResult listPjProfitMoney(@RequestParam(value = "time",required = false)String time) throws ParseException {
        List<Map<String,Object>> hashMapList = new ArrayList<>();
        Calendar calendar = Calendar.getInstance();
        Map<String,Object> totalMap = new HashMap<>();
        String totalOutMoney = "0";
        String totalInMoney = "0";
        DecimalFormat df = new DecimalFormat("0.00##");
        if(time!=null && time.length()>0){
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String date = time+"-01-01 00:00:00";
            Date lastDate = sdf.parse(date);
            for (int i = 0; i < 12; i++) {
                HashMap<String,Object> hashMap = new HashMap<>();
                String workDate = DateUtil.Date2String(lastDate, "yyyy-MM");
                List<Map<String, Object>> maps = provideRecordsService.selectSumProfitMoney(workDate);
                hashMap.put("month",workDate.substring(5,7));
                hashMap.put("data",maps);
                hashMapList.add(hashMap);
                if(maps.get(0)!=null){
                    if(maps.get(0).get("outMoney")!=null){
                        totalOutMoney = df.format(Double.valueOf(totalOutMoney)+Double.valueOf(maps.get(0).get("outMoney").toString()));
                    }
                    if(maps.get(0).get("inMoney")!=null){
                        totalInMoney = df.format(Double.valueOf(totalInMoney)+Double.valueOf(maps.get(0).get("inMoney").toString()));
                    }
                }
                lastDate = DateUtil.dateAddMonth(lastDate,1);
            }
        }else{
            calendar.setTime(new Date());
            calendar.set(calendar.MONTH,0);
            Date lastDate = calendar.getTime();
            for (int i = 0; i < 12; i++) {
                HashMap<String,Object> hashMap = new HashMap<>();
                String workDate = DateUtil.Date2String(lastDate, "yyyy-MM");
                List<Map<String, Object>> maps = provideRecordsService.selectSumProfitMoney(workDate);
                hashMap.put("month",workDate.substring(5,7));
                hashMap.put("data",maps);
                hashMapList.add(hashMap);
                if(maps!=null&&maps.size()>0){
                    if(maps.get(0).get("outMoney")!=null){
                        totalOutMoney = df.format(Double.valueOf(totalOutMoney)+Double.valueOf(maps.get(0).get("outMoney").toString()));
                    }
                    if(maps.get(0).get("inMoney")!=null){
                        totalInMoney = df.format(Double.valueOf(totalInMoney)+Double.valueOf(maps.get(0).get("inMoney").toString()));
                    }
                }
                lastDate = DateUtil.dateAddMonth(lastDate,1);
            }
        }
        totalMap.put("totalOutMoney",totalOutMoney);
        totalMap.put("totalInMoney",totalInMoney);
        hashMapList.add(totalMap);
        return AjaxResult.success(hashMapList);
    }

}
